
define([
  './custom/widgets/js/yufpOrgTree.js',
  './custom/plugins/YufpMgrSelector.js',
  './custom/widgets/js/yufpExtTree.js',
  './libs/swiper/swiper-3.4.2.jquery.min.js'  

], function (require, exports) {
  exports.ready = function (hashCode, data, cite) { 
    // 注册该功能要用到的数据字典
    yufp.lookup.reg('MODEL_TYPE','REPY_MOD','GURT_MOD');
    // 创建virtual model
	var custNo = data.cust.custNo;//获取从其他页面跳转过来所携带的参数(客户号) 
    yufp.custom.vue({
      el: cite.el,
      // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
      data: function () {
        return {
		  themeColor: yufp.frame.baseFrame.themes.color,
		  custObjInfo:{},
		  optionOne:{},
		  optionTwo:{},
		  optionThree:{},
		  optionFour:{},
		  userImageUrl:'',
          judgeUser:true,
		  activeName: 'first',
		  activeNameTab: 'one',
          custData:{condition: JSON.stringify({
			  custNo:custNo
            })},
          depDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustDepInfo',
		  loanDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustLoanInfo',
		  fincDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustFincInfo',
		  fundDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustFundInfo',
		  bxDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustBxInfo',
		  xtDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustXtInfo',
		  custHisDataUrl:backend.msmFrontWebService + '/api/custviewInfo/getCustGridBelongHis',
          headers: {
            'Authorization': 'Bearer' + yufp.service.getToken()
          },
          dialogCustHistoryVisible: false,
		  sendMesVisible:false,
		  progressVisible:true,
          formDisabled: false,
          loading: false,
		  custHistoryRecordInfo:[],
		  //关联关系
		  familyInfo:[],
		  amtflowInfo:[],  
		  gurtInfo:[],
		  investInfo:[], 		   
		  timelineItems:[], //时间轴
		  messageApproveUrl: '/api/marketCustGroup/getApprove' ,
		  messageApproveParam: {
		      orgId:yufp.session.org.id
		  }
        };
      },
      created:function (){
		this.custAssettime();
		this.custAssetYearVolatility();
		this.custSxAmt();
		this.custBaseInfo();
		this.custTagInfo();
      },
      // 钩子
      mounted: function () {
      },
      methods: {
		custAssettime:function(){//资产时点余额-环形图
				var me = this; 
				var arrName=['存款', '贷款', '理财', '基金', '保险', '信托'];
				yufp.service.request({
				  url: backend.msmFrontWebService + '/api/custviewInfo/getAssetTime',
				  method: 'get',
				  data: {
				    condition: JSON.stringify({
						custNo:custNo
				    })
				  },
				  callback: function (code, message, response) {
					  	var sumBal=0;
						var array = response.data;
						if(array.length==0){
							array.push({ value: 0, name: '存款' });
							array.push({ value: 0, name: '贷款' });
							array.push({ value: 0, name: '理财' });
							array.push({ value: 0, name: '基金' });
							array.push({ value: 0, name: '保险' });
							array.push({ value: 0, name: '信托' });
						}
						for(var i = 0; i<array.length;i++){
							 sumBal += array[i].value;
						}
						var option1= {
						  color: ['#687AEE', '#FB8D12', '#D66A6F', '#95D15F', '#3AB0EB', '#55007f'],
							title:{
								text: '资产时点余额 : '+sumBal+'万',
								subtext: '',
								x:'center'
							},
						  tooltip: {
						    trigger: 'item',
						    formatter: '{a} <br/>{b}: {c} 万({d}%)'
						  },
						  legend: {
								show:true,
								orient: 'horizontal',
								x: 'left',
								left: 'center',
								bottom: 0,
								data:arrName
						  },
						  series: [
						    {
						      name: '资产时点余额占比',
						      type: 'pie', 
						      radius :  ['30%', '60%'],
						      avoidLabelOverlap: false,
						      label: {
						        normal: {
									show: true,
									position: 'top',
									formatter: '{b}: {c}万({d}%)',
									textStyle: {
										color: '#000',
									}
						        }
						      },
						      data: array
						    }
						  ]
						};
						me.optionOne=option1;
				  }
				});
		 },
        custAssetYearVolatility:function(){//客户资产--半年波动图
				var me = this; 
				yufp.service.request({
				  url: backend.msmFrontWebService + '/api/custviewInfo/getAssertsChangeMonthTrend',
				  method: 'get',
				  data: {
				    condition: JSON.stringify({
						custNo:custNo
				    })
				  },
				  callback: function (code, message, response) {
					var arr = response.data; 
					var astArr = [];//时点
					var aumArr = [];//月日均
					var etlDate = [];
					if(arr.length==0){ 
					}
					for(var i = 0; i<arr.length;i++){
						etlDate.push(arr[i].etlDt);
						astArr.push(arr[i].sumasset);
						aumArr.push(arr[i].aum);
					}
					var option4 = {
					            color: [me.themeColor],
					            tooltip: {
					              trigger: 'axis'
					            },
								legend: {
									top:'0',
								    data:['资产时点(万元)','AUM月日均(万元)'],
								    padding:[15,0,0,10],
								    textStyle:{
								        color:'#666'
								    }
								},
					            grid: {
					              top: 8,
					              left: 0,
					              right: 0,
					              bottom: 0,
					              containLabel: true
					            },
					            textStyle: {
					              color: '#949494'
					            },
					            xAxis: {
					              type: 'category',
					              data: etlDate,
					              axisTick: {show: false},
					              axisLine: {
					                lineStyle: {
					                  color: '#E0E0E0'
					                }
					              }
					            },
					            yAxis: {
					              type: 'value',
					              axisLine: {
					                lineStyle: {
					                  color: '#E0E0E0'
					                }
					              },
					              axisTick: {show: false},
					              splitLine: {
					                lineStyle: {
					                  color: '#EDEDED'
					                }
					              }
					            },
					            series: [
					              {
									name:'资产时点(万元)',
					                type: 'line',
					                smooth: true,
									barWidth: '30%',
					                data: astArr,
					                itemStyle: {
					                  normal: {
										color:'#fab130',
					                    lineStyle: {
					                      width: 3
					                    }
					                  }
					                }
					              },
								  {
									name:'AUM月日均(万元)',
								    type: 'line',
								    smooth: true,
								  	barWidth: '30%',
								    data: aumArr,
								    itemStyle: {
								      normal: {
										color:'#0065d2',
								        lineStyle: {
								          width: 3
								        }
								      }
								    }
								  }
					            ]
					        };
					me.optionFour=option4;
				  }
				}); 
				
		},
		custSxAmt:function(){ //资产负债时点余额-环形图
			var me = this; 
			var arrName=['已用额度', '剩余额度'];
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getliabilityInfo',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) {
					var sumBal=0;
					var array = response.data;
					if(array.length==0){
						array.push({name:'已用额度',value:0},{name:'剩余额度',value:0});
					}
					for(var i = 0; i<array.length;i++){
						 sumBal += array[i].value;
					}
					var option1= {
					  color: ['#687AEE', '#FB8D12'],
						title:{
							text: '授信额度 : '+sumBal+'万',
							subtext: '',
							x:'center'
						},
					  tooltip: {
					    trigger: 'item',
					    formatter: '{a} <br/>{b}: {c} 万({d}%)'
					  },
					  legend: {
							show:true,
							orient: 'horizontal',
							x: 'left',
							left: 'center',
							bottom: 0,
							data:arrName
					  },
					  series: [
					    {
					      name: '授信余额占比',
					      type: 'pie',
					      radius :  ['30%', '60%'],
					      avoidLabelOverlap: false,
					      label: {
					        normal: {
								show: true,
								position: 'top',
								formatter: '{b}: {c}万({d}%)',
								textStyle: {
									color: '#000',
								}
					        }
					      },
					      data: array
					    }
					  ]
					};
					me.optionThree=option1;
			  }
			});
		},
		custBaseInfo:function(){//客户基本信息
			var _this = this;
			_this.custNo=custNo;
			var obj = {
			};
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getCustomerInformation',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) {
				  var baseInfo = response.data;
				  obj.custName=('custName' in baseInfo[0])?baseInfo[0].custName:'';
				  obj.isPuhui=('isPuhui' in baseInfo[0])?baseInfo[0].isPuhui:'';
				  obj.lnBal=('lnBal' in baseInfo[0])?baseInfo[0].lnBal:'';
				  obj.isSun=('isSun' in baseInfo[0])?baseInfo[0].isSun:'';
				  obj.fincWind=('fincWind' in baseInfo[0])?baseInfo[0].fincWind:'';
				  obj.flag=('flag' in baseInfo[0])?baseInfo[0].flag:'';
				  obj.custLevel=('custLevel' in baseInfo[0])?baseInfo[0].custLevel:'';
				  obj.personRisk=('personRisk' in baseInfo[0])?baseInfo[0].personRisk:'';
				  obj.gridName=('gridName' in baseInfo[0])?baseInfo[0].gridName:'';
				  obj.isYyzz=('isYyzz' in baseInfo[0])?baseInfo[0].isYyzz:'';
				  obj.oneWord=('oneWord' in baseInfo[0])?baseInfo[0].oneWord:'';
				  obj.mgrName=('mgrName' in baseInfo[0])?baseInfo[0].mgrName:'';
				  obj.sex=('gndrCd' in baseInfo[0])?baseInfo[0].gndrCd:'';
				  if(obj.sex=='1'){
					  _this.userImageUrl='themes/common/images/wordcloud/6.png';
				  }else if(obj.sex=='2'){
					  _this.userImageUrl='themes/common/images/wordcloud/7.png';
				  }
				  _this.custObjInfo = obj;
			  }
			});
		},
		custTagInfo:function(){//客户标签(持有产品)信息
			var me = this;
			var currentPageId  = (cite.el).split(" ")[0]; 
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getCustTags',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) {
				  	if(response.data.length!='0'){
				  		var tagsInfo = (response.data)[0];
				  		for(var tag in tagsInfo){
				  			if(tagsInfo[tag]=="1"){
				  				$(currentPageId+' #'+tag).addClass("yu-tagBgStyle");
				  			}
				  			if(tagsInfo[tag]=="0"){
				  				$(currentPageId+' #'+tag).addClass("yu-tagBgNotStyle");
				  			}
				  		} 
				  	}else{
				  		$(currentPageId+' .el-tag').addClass("yu-tagBgNotStyle");
				  	}
			  }
			});
		},
		familyRelationInfo:function(){//家庭关系
			var me = this;
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getFmyRel',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) {  
				me.familyInfo = response.data;
			  }
			}); 
		},
		moneyFlow:function(){//资金流动
			var me = this;
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getFndFlow',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) { 
				me.amtflowInfo = response.data;
			  }
			}); 
		},
		outboundInvestment:function(){ //对外投资
			var me = this;
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getExtIvs',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) { 
				me.investInfo = response.data;
			  }
			}); 
		},
		gurtInfomation:function(){//担保关系
			var me = this;
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getGurtRel',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo
			    })
			  },
			  callback: function (code, message, response) { 
				me.gurtInfo = response.data;
			  }
			}); 
		},
		handleClick: function (tab, event) { 		
		},
		handleClickTab: function (tab, event) {
			if(tab.index=='1'){
				this.familyRelationInfo();//家庭关系
				this.moneyFlow();//资金流向
				this.outboundInvestment();//对外投资
				this.gurtInfomation();//担保关系 
			}else if(tab.index=='2'){ 
				this.timeLine();//时间轴
			}
		},
		searchCustBelongHistory:function(){//网格客户归属历史查看
			var me = this;
			me.dialogCustHistoryVisible = true;
		},
		sendMessage:function(){//短信发送功能
			if(yufp.session.roles[0].code=='R0001' || yufp.session.roles[0].code=='R0002'){//只有客户经理才能呼出短信面板发送短信
				this.sendMesVisible = true;
				if (this.$refs.templetForm != null) {
				    this.$refs.templetForm.resetFields();
				}
			}else{
				this.$message({message: '您无权限进行此操作!', type: 'warning'}); 
			}
		},
		calling:function(){//拨号功能
			var _this = this;
			 _this.$message({message: '正在研发中....', type: 'warning'});
		},
		timeLine:function(){  //时间轴滑动开启样式设置
			var mySwiper = new Swiper(".swiper-container", {
					slidesPerView: 4, /*默认是显示4个*/                
					initialSlide: 0, /*默认从第几个显示，999是为了让右边没有*/
					spaceBetween: 0, /*间距*/
					speed: 500,/*速度*/
					mousewheelControl: true,/* 开启鼠标滚轮滑动*/
					/*修复页面初始化时无法滑动问题*/
					observer:true,
					observeParents:true
					}) 
		},
		timeaxs:function(value){
			//根据value值不同传入不同参数值获取相应的时间轴
			var me = this;
			yufp.service.request({
			  url: backend.msmFrontWebService + '/api/custviewInfo/getTimeAxs',
			  method: 'get',
			  data: {
			    condition: JSON.stringify({
					custNo:custNo,
					evTp:value
			    })
			  },
			  callback: function (code, message, response) { 
				me.timelineItems = response.data;
			  }
			}); 
		},
		getTemInfo: function(event){//短信流程面板中模板内容随着模板序号改变而改变
		    if(event!=null){
		        var self = this;
		        var modelType = event;
		        yufp.service.request({
		            method: 'GET',
		            url: '/api/marketCustGroup/selectMessageTemInfo',
		            data: {modelType: modelType	},
		            callback: function(code, message, response) {
		                var data = response.data;
		                var modelInfo =data.modelInfo;
		                self.$refs.templetForm.formdata.modelInfo=data.modelInfo;
		            }
		        });
		    }
		},
		addSubmit: function() {//短信发送流程提交操作
			var id = this.getIdUtil();
		    var vm = this;
		    this.$refs.templetForm.validate(function(valid) {
		        if (valid) {
		            vm.loading = true;
		            var modelType = vm.$refs.templetForm.formdata.modelType;
		            var modelInfo = vm.$refs.templetForm.formdata.modelInfo;
		            var approverNo = vm.$refs.templetForm.formdata.approverNo;
		            var addParam = {
		                userId: yufp.session.userCode,
		                userName: yufp.session.userName,
		                modelType: modelType,
		                modelInfo: modelInfo,
		                approverNo: approverNo,
		                custGroupNo: id,
		                gridId: ''
		            };
		            yufp.service.request({
		                method: 'POST',
		                url: '/api/marketCustGroup/insertApprove',
		                data: JSON.stringify(addParam),
		                callback: function(code, message, response) {
		                    if (code == 0) {
		                        vm.$message({
		                            message: '保存成功',
		                            type: 'success'
		                        });
		                        vm.sendMesVisible = false;
		                    }
		                    vm.loading = false;
		                }
		            });
		        }
		    });
		},
		addCancel: function() {//短信发送流程取消操作
		    this.sendMesVisible = false;
		    if (this.$refs.templetForm != null) {
		        this.$refs.templetForm.formdata = {};
		    }
		},
		getIdUtil: function(){//获取随机ID
			var num = '';
			for(var i=0;i<3;i++){
			    num+=Math.floor(Math.random()*10);
			}
			var newtime = new Date().getTime()+'';//获取当前时间戳
			var time = newtime.substr(2); 
			var y = new Date().getFullYear();
			return y+time+num;
		}
      }
    });
  };

  // 消息处理
  exports.onmessage = function (type, message) { };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {};
});
